window.onload = () => {
    let btn_login = document.getElementById('login');
    let btn_regist = document.getElementById('regist');
    // 登录
    btn_login.onclick = async () => {
        const username = document.getElementsByName('username')[0];
        const password = document.getElementsByName('password')[0];
    }

    // 注册
    btn_regist.onclick = async () => {
        const username = document.getElementsByName('username')[1];
        const password = document.getElementsByName('password')[1];

        if (username.value && password.value) {
            let res = await axios.post('http://localhost:4000/regist', {
                username: md5(username.value),
                password: md5(password.value)
            })
            alert(res.data.message);
            this.localStorage.setItem('token', res.data.token);
            console.log(res);
            window.location = 'http://localhost:4000';
        } else {
            alert('用户名和密码不能为空!');
        }
    }
}